home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / texmac.zip / SPPRINT.SPM < prev    next >
Text File  |  1991-08-31  |  17KB  |  536 lines

  1. ; Formatter related macros and menus
  2. ; -----------------------------------------------------------------
  3. ; Deletions
  4. ; -----------------------------------------------------------------
  5. ; Variables
  6. ; -----------------------------------------------------------------
  7. ; Forward Declarations
  8. ; -----------------------------------------------------------------
  9. ; General Macros
  10.  
  11. PrintGuess :        ; try to guess which pass this file should print on
  12.     mark {        ; RUN BEFORE CHANGING BUFFERS!!!
  13.         if (lines > GuessCutOff) (2 return)
  14.         r toend
  15.         if ('@' csearch) (2 return)
  16.         r toend
  17.         if ('^O' csearch) (2 return)
  18.         r toend
  19.         if ('^D' csearch) (2 return)
  20.         r toend
  21.         if ('^V' csearch) (2 return)
  22.         }
  23.     1
  24.  
  25. PrintOptions:    ; fwd declare for Infomerge
  26.  
  27. ; These functions use QK to hold various parameters for Spmerge.
  28. ; The format of QK is:
  29. ; letterfile<ffh>datafile<ffh>sortorder<ffh>selectioncriteria
  30. ; init sets the initial contents of QK to:
  31. ; <ffh><ffh><ffh>
  32. ; The routines below pick out the particular field required, and return
  33. ; the results in Q0.  Defaults are made if nothing has been set yet
  34.  
  35. InfoLetterFile :
  36.     mark {
  37.         to QK
  38.         if current = 0ffh {    ; if no letter file set yet
  39.             set Q0 cdstrip Q0        ; set default
  40.             insert Q0                ; save default
  41.             }
  42.         else {set Q0 "" copy to (current = 0ffh) Q0}    ; get name out
  43.         }
  44.  
  45. InfoLetter : ; Return w/Q0 = letter file name
  46.     set Q0 fname    ; to build default
  47.     InfoLetterFile    ; can't combine, cause we need fname in Q0
  48.                 ; and InfoData calls InfoLetterFile from within QK,
  49.                 ; and That would give an fname of null.
  50.  
  51. InfoLetterSet : ; prompt for Letter file name and place in QK
  52.     set Q0 cdstrip fname    ; get a default
  53.     message "\nLetter file to print: " set Q0
  54.     set Q0 cdstrip flist Q0            ; it looks weird, but works!
  55.     0 QCap        ; file name in CAPS
  56.     mark {
  57.         to QK
  58.         erase to current = 0ffh    ; prepare for new name
  59.         insert Q0
  60.         }
  61.  
  62. InfoData : ; Return w/Q0 = Data file name
  63.     set Q0 fname    ; in case required to build default
  64.     mark {
  65.         to QK
  66.         to current = 0ffh c        ; start of data file name
  67.         if current = 0ffh {    ; if no data file set yet
  68.             set Q0 "DEFAULT.REC"
  69. ;; Next 2 lines would make default 'fname.rec'
  70. ;            InfoLetterFile            ; set default
  71. ;            set Q0 fchange "%.REC" Q0
  72.             insert Q0                ; save default
  73.             }
  74.         else {copy to (current = 0ffh) Q0}    ; get name out
  75.         }
  76.  
  77. InfoDataSet : ; prompt for Data file name and place in QK
  78.     InfoData    ; get a default
  79.     message "\nData file to merge: " set Q0
  80.     set Q0 cdstrip flist Q0            ; it looks weird, but works!
  81.     0 QCap        ; file name in CAPS
  82.     mark {
  83.         to QK
  84.         to current = 0ffh c
  85.         erase to current = 0ffh    ; prepare for new name
  86.         insert Q0
  87.         }
  88.  
  89. InfoSortOrder : ; Return w/Q0 = Sort Order
  90.     mark {
  91.         to QK
  92.         to current = 0ffh c        ; start of data file name
  93.         to current = 0ffh c        ; start of Sort order info
  94.         if current = 0ffh {    ; if no sort order entered
  95.             set Q0 ""
  96.             }
  97.         else {copy to (current = 0ffh) Q0}    ; sort order to Q0
  98.         }
  99.  
  100. InfoOrderSet :
  101.     InfoSortOrder    ; get a default
  102.     message "\nSort order: " set Q0
  103.     mark {
  104.         to QK
  105.         to current = 0ffh c
  106.         to current = 0ffh c
  107.         erase to current = 0ffh    ; prepare for new sort order
  108.         insert Q0
  109.         }
  110.  
  111. InfoSortSpec : ; Return w/Q0 = Sort Criteria
  112.     mark {
  113.         to QK
  114.         to current = 0ffh c        ; start of data file name
  115.         to current = 0ffh c        ; start of Sort order info
  116.         to current = 0ffh c        ; start of Sort Criteria info
  117.         if isend {    ; if no sort criteria entered
  118.             set Q0 ""
  119.             }
  120.         else {copy toend Q0}    ; sort criteria to Q0
  121.         }
  122.  
  123. InfoSpecSet :
  124.     InfoSortSpec    ; get a default
  125.     message "\nRecord selection criteria: " set Q0
  126.     mark {
  127.         to QK
  128.         to current = 0ffh c
  129.         to current = 0ffh c        ; start of Sort order info
  130.         to current = 0ffh c        ; start of Sort Criteria info
  131.         erase toend            ; prepare for new name
  132.         insert Q0
  133.         }
  134.  
  135. InfoMerge :        ; preserve PrintDest, but allow temp change
  136.     (PrintDest -> SaveDest $)    ; save destination, preserve argument
  137.     -> PrintDest
  138.     InfoLetter
  139.     mark (if (buffind Q0 && modf) FileSave)    ; make sure file is current
  140.     InfoData
  141.     mark (if (buffind Q0 && modf) FileSave)    ; make sure file is current
  142.     mark {        ; build command in Q6
  143.         to Q6 clear
  144.         insert "SPMERGE "
  145.         InfoLetter insert Q0
  146.         insert " -r "
  147.         InfoData insert Q0
  148.         insert " "
  149.         if (DataFormat) insert "-remditto "
  150.         if (FirstRec != 1) (FirstRec put "-startrec %d ")
  151.         if (LastRec) (LastRec put "-endrec %d ")
  152.         InfoSortOrder if length Q0 {    ; if a sort order spec'd add it
  153.             insert "-sort "
  154.             insert Q0 insert " "
  155.             }
  156.         InfoSortSpec if length Q0 {    ; if selection criteria exists add it
  157.             insert "-select "
  158.             insert Q0 insert " "
  159.             }
  160.         insert "-p "
  161.         }
  162.     6 PrintOptions    ; add printoptions to end
  163.     SaveDest ->PrintDest    ; restore the destination as it was
  164.     ; formatter can't add '-z or -p=' switches so add them here ourselves
  165.     ; otherwise, they are added at the front of the command line.
  166.     mark {
  167.         to Q6
  168.         toend
  169.         insert "-z " $
  170.         if length printer {
  171.             insert "-p=" $
  172.             insert printer
  173.             }
  174.         }
  175.     if record KeyRecordEnd    ; allow graceful keyrecord endings
  176.     set Q0 "spmerge.com" NeedDisk
  177.     PArg + 6 call Q6
  178.  
  179. LimitLength : ; truncates a string in Q0 to length passed to it. adding '...'
  180.     ->int x        ; if it truncated.
  181.     if ((length Q0) <= x) return    ; no truncation necessary
  182.     mark {
  183.         to Q0
  184.         while (offset != (x-3)) c    ; move to position
  185.         erase toend                ; remove excess
  186.         insert "..."                    ; add ellipses
  187.     }
  188.  
  189. ; contextual help
  190. InfoGoHelp:
  191. InfoPreviewHelp:
  192. InfoFirstHelp:
  193. InfoLastHelp:
  194.  
  195. InfoMergeMenu :
  196.     if FloppyDisk error "You can't run InfoMerge within Sprint on floppy systems"
  197.     do {
  198.         menu "Merge" {
  199.         "Go!"                InfoGoHelp draw PrintDest InfoMerge,
  200.         "Screen Preview"        InfoPreviewHelp draw 2 InfoMerge,
  201.         "_",
  202.         InfoLetter    "Letter File\>" Q0 InfoLetterSet,
  203.         InfoData        "Record File\>" Q0 InfoDataSet,
  204.         "_",
  205.         DataFormat    "Data Format\>%[STANDARD%:BASIC%]"
  206.             !DataFormat ->DataFormat SetOvlModf,
  207.         FirstRec        "Initial Record\>%d"
  208.             InfoFirstHelp 0 rangeget 32767 "Start with record" ->FirstRec,
  209.         LastRec        "Ending Record\>%[LAST%:%d%]"
  210.             InfoLastHelp 0 rangeget 32767 "Last record to merge (0 = end)" ->LastRec,
  211.         "_",
  212.         (InfoSortOrder 17 LimitLength)
  213.                 "Order\>" Q0 InfoOrderSet,
  214.         (InfoSortSpec    14 LimitLength)
  215.                 "Criteria\>" Q0 InfoSpecSet
  216.             }
  217.         }
  218.  
  219. Paginate :
  220.     if (IsOnlyRuler) return
  221.     if NeedSave FileSave
  222. ;    if (modf=1 || (!length fname)) FileSave
  223. ;    1 -> RestartMode
  224.     if record KeyRecordEnd    ; allow graceful keyrecord endings
  225.     status "\nPaginating..."
  226.     set Q0 "spedit.exe" NeedDisk
  227.     PArg+8 call "spfmt -l=log.$$$ -p0" cdstrip fname
  228.     Restart  ; I think this only happens because it's built into Sprint?
  229.  
  230. PrintingTo : PrintDest message "\nReady to send output to %[printer%;file%;screen%;queue%]"
  231.  
  232. ; ----- a replacement for PrintMenu in SP.SPM -----
  233.  
  234. ClearQI : mark { to QI {
  235.       clear 253 insert    ; marker
  236.       0 insert            ; PrintDest = printer, of file, screen, queue
  237.       0 insert            ; PrintPass = auto
  238.       1 insert            ; NumCopies = 1
  239.       0 insert            ; PagePause  = no
  240.       0 insert            ; LogErrors    = no
  241.       0 insert            ; Plain  = no
  242.       0 insert            ; AutoFill   = no
  243.       0 insert            ; spooling  = no    ; RDT, not used see PrintDest
  244.       254 insert          ; 1 font   = <default>
  245.           insert "PS"
  246.       254 insert          ; 2 start  = <first>
  247.       254 insert          ; 3 end    = <last>
  248.       254 insert          ; 4 printer name
  249.       254 insert          ; 5
  250.       254 insert        ; 6 Tex Compose cline
  251.         insert  "Tex "  ;     or Latex or Tex &lplain
  252.       254 insert        ; 7 Tex DVI print cline
  253.         insert "dvieps -x.75in -y0in "
  254.       254 insert        ; 8 Tex TTY cline
  255.         insert "dvi2tty -e-12 -w120 "
  256.       } }
  257.  
  258. CheckQI : mark { to QI if (current != 253) ClearQI }
  259.  
  260. ; get the n'th numeric entry, return in the argument
  261. GetQINum : ->int n CheckQI mark { to QI n repeat c current }
  262.  
  263. ; set the n'th numeric entry to the value of x
  264. SetQINum : ->int n CheckQI mark { to QI n repeat c x->current }
  265.  
  266. ; get the n'th string entry, return in QD
  267. GetQIStr : ->int n CheckQI
  268.       mark { to QI n repeat { 254 csearch c }
  269.       copy to (current = 254) QD }
  270.  
  271. ; set the n'th string entry to the value of QD
  272. SetQIStr : ->int n CheckQI
  273.       mark { to QI n repeat { 254 csearch c }
  274.       erase to (current = 254) insert QD }
  275.  
  276. GetPrinter :  5 GetQIStr $ if !length QD set QD "<default>"
  277.     ; set QD printer^ 
  278.  
  279. SetPrinter : 10 set printer flist "*.spp" (set QD printer 5 SetQIStr)
  280.  
  281. GetFont : 1 GetQIStr if !length QD set QD "<default>"
  282.  
  283. SetFont : set QD pickfont 1 SetQIStr
  284.  
  285. CurrentDest : (PrintDest+1)%4 -> PrintDest
  286.  
  287. GetStart : 2 GetQIStr if !length QD set QD "<first>"
  288.  
  289. SetStart : 2 GetQIStr message "Starting Page (or TOC): " set QD 2 SetQIStr
  290.  
  291. GetEnd : 3 GetQIStr if !length QD set QD "<last>"
  292.  
  293. SetEnd : 3 GetQIStr message "Ending Page: " set QD 3 SetQIStr
  294.  
  295. ErasePages :    ; Depaginate - remove all temporary page breaks
  296.     mark {
  297.         r toend
  298.         while ('^L' csearch) (toeol if (current != '^J') (del erase tosol))
  299.         }
  300.     readpage    ; make editor know page # is different
  301.  
  302. ; add print options to end of the q-register given as the argument (!= 0)
  303. ; note: the 'printer' value is appended by 'call' when bit 1 of PArg is set
  304. ; note: all options are in QI, except PrintDest which is set before
  305. PrintOptions :
  306.       mark {
  307.            ->int qreg
  308.        int GuessResult
  309.            (PrintGuess -> GuessResult $) ; check before switching buffers
  310. ;    1 -- PrintDest is global, and set in Menu
  311.            2 GetQINum -> int PrintPass
  312.            3 GetQINum -> int NumCopies
  313.            4 GetQINum -> int PagePause
  314.            5 GetQINum -> int LogErrors
  315.            6 GetQINum -> int Plain
  316.            7 GetQINum -> int AutoFill
  317.  
  318.        if (PrintDest = 1)
  319.                 { set Q0 "-v " }
  320.            else if (PrintDest >= 2) ; file or queue output
  321.                 {
  322.         set Q0 "%.PRN" mark(to Q0 insert home)    ; easier to cleanup if in one dir.
  323. ;                set Q0 cdstrip fchange "%.PRN" fname    ; default file name
  324.                 set Q0 flist Q0
  325.                 0 QCap
  326.                 do   {
  327.                      message "\nOutput file name: " set Q0
  328.                      set Q0 flist Q0
  329.              if PrintDest = 3 (set Q4 Q0)    ; preserve for my spool technique
  330. ;             else set Q4 ""            ; use as flag
  331.                      if (!(32 exist Q0) || ask "Overwrite existing file?")
  332.                           {
  333.                           to Q0 insert "-o=" toend insert " " break
  334.                           }
  335.                      }
  336.                 }
  337.  
  338.            else set Q0 ""    ; no trailing switches
  339.            qreg qswitch toend insert Q0
  340.            1 GetQIStr
  341.            if (length QD)
  342.                 { insert "-f=" insert QD insert " " }
  343.            2 GetQIStr
  344.            if (mark ( to QD 1 match "toc" ))
  345.                 { insert "-page=0 " }         ; to print TOC only
  346.            else {
  347.                 if (length QD) (insert "-start=" insert QD insert " ")
  348.                 3 GetQIStr
  349.                 if (length QD) (insert "-stop=" insert QD insert " ")
  350.                 }
  351.  
  352.            if ((NumCopies > 1) && (PrintDest != 2)) (NumCopies put "-%d ")
  353.            if (PagePause) (insert "-pause ")
  354.            if (Plain) (insert "-p ")
  355.            if (AutoFill) (insert "-f ")
  356.            if (LogErrors) (insert "-l ")
  357.            if (PrintPass)
  358.                 (PrintPass put "-p%d ")
  359.            else
  360.                 (GuessResult put "-p%d ")
  361.            tabsize put "-t=%d "
  362.            }
  363.  
  364. PrintDoc :        ; argument is device to print to
  365.     -> PrintDest -> int Dest
  366.     5 GetQIStr set printer QD    ; RDT, get stored printer name
  367.     if (IsOnlyRuler) return
  368.     ; (modf=1 || (!length fname) || (!exist fname))
  369.     if NeedSave FileSave
  370.     if (!length fname) abort        ; if file save didn't complete
  371.     set Q6 "spfmt "
  372.     6 PrintOptions
  373.     if record KeyRecordEnd    ; allow graceful keyrecord endings
  374. ;    set Q0 "spedit.exe" NeedDisk
  375.         SetOvlModf      ; save damn variables in Ovl file
  376.     if (PrintDest = 3) ( ; 
  377.         PArg call Q6 cdstrip fname
  378. ;        call "print /p " Q4    ; Q4 now holds output file name, cleanup in autoexec
  379.         )    ; Only Restart can do anything after BigDos 16 call
  380.     else (PArg+8 call Q6 cdstrip fname)    ; restart causes ignorance of printdest?
  381.  
  382. WPPrintMenu : menu "SPFMT (Scribe) Print" {
  383.       "Go!"                         (1 GetQINum) PrintDoc,
  384.       "View on screen"              1  PrintDoc,
  385. ;      "Merge"                       InfoMergeMenu,
  386.       "Break into pages"            Paginate,
  387.       "Remove page breaks"          ErasePages,
  388.       "_Print Settings",
  389.       "Default settings"            if ask "Are you sure (Y,N,ESC)? "
  390.                                          { ClearQI set printer "" } abort,
  391.       GetPrinter "Printer\>" QD     SetPrinter abort,
  392.       GetFont "Font\>" QD           SetFont abort,
  393.       (1 GetQINum) "Output to\>%[PRINTER%;SCREEN%;FILE%;QUEUE%]"
  394.                                     ((1 GetQINum)+1)%4->x 1 SetQINum abort,
  395.       "_",
  396.       GetStart "Start Page\>" QD     SetStart abort,
  397.       GetEnd "End Page\>" QD         SetEnd abort,
  398.       "_",
  399.       (2 GetQINum) "A number of pAsses\>%[AUTO%;1%;2%;3%]"
  400.                                     ((2 GetQINum)+1)%4->x 2 SetQINum abort,
  401.       (3 GetQINum) "N Number of copies\>%d"
  402.                                     1 rangeget 250 "Number of Copies" ->x
  403.                                     3 SetQINum abort,
  404.       (4 GetQINum) "C Cut sheets\>%[ NO%:YES%]"
  405.                                     !(4 GetQINum)->x 4 SetQINum abort,
  406.       (5 GetQINum) "L Log errors to file\>%[ NO%:YES%]"
  407.                                     !(5 GetQINum)->x 5 SetQINum abort,
  408.       (6 GetQINum) "U Unformatted Print\>%[ NO%:YES%]"
  409.                                     !(6 GetQINum)->x 6 SetQINum abort,
  410.       (7 GetQINum) "W Wordwrap Ascii Files\>%[ NO%:YES%]"
  411.                                     !(7 GetQINum)->x 7 SetQINum abort
  412.       }
  413.  
  414. centry : if select (
  415.     int WasBefore 0
  416.         aftermark ? swapmark : (1-> WasBefore)
  417.         insert Q0 "{"
  418.         swapmark
  419.         insert "}"
  420.         WasBefore ? swapmark    ; get back in front
  421.         0->select
  422.         )
  423.     else (insert Q0 "{}" r c)
  424.  
  425. bentry : mark (0 qswitch del)
  426.     int WasBefore 0    ; flag to stay at the current end of blck
  427.     if select (
  428.         aftermark ? swapmark : (1-> WasBefore)
  429.         "@begin(" insert Q0
  430.         ")\n"
  431.         swapmark
  432.         "@end(" insert Q0
  433.         ")\n"
  434.         if WasBefore swapmark    ; get back to front end
  435.         0->select
  436.         )
  437.     else (
  438.         "@begin(" insert Q0 ")\n\n@end(" insert Q0 ")\n" Up Up
  439.         )
  440.  
  441. TypefacesMenu : imenu "Typefaces" (
  442.     "@B (bold)" set Q0 "@b",
  443.     "@Big",
  444.     "@I (italics)" set Q0 "@i",
  445.     "@P (bold italics)" set Q0 "@p",
  446.     "@R (regular)" set Q0 "@r",
  447.     "@T (typewriter)" set Q0 "@t",
  448.     "@UX (underscore)" set Q0 "@ux",
  449.     "@U (U/characters)" set Q0 "@u",
  450.     "@UN (U/letters+digits)" set Q0 "@un",
  451.     "@+ (superscript)" set Q0 "@+",
  452.     "@- (subscript)" set Q0 "@-")
  453.     centry
  454.  
  455. DivisionsMenu : imenu "Divisions" (
  456.     "@MajorHeading",
  457.     "@Heading",
  458.     "@SubHeading",
  459.     "@Chapter",
  460.     "@Section",
  461.     "@SubSection",
  462.     "@Paragraph",
  463.     "@Appendix",
  464.     "@AppendixSection")
  465.     centry
  466.  
  467. LayoutMenu : imenu "Layout Commands" (
  468.     "@Center" bentry,
  469.     "@Flushright" bentry,
  470.     "@Quotation" bentry,
  471.     "X-@Example" set Q0 "@Example" bentry,
  472.     "@Description" bentry,
  473.     "@Enumerate" bentry,
  474.     "@Itemize" bentry,
  475.     "@Level" bentry,
  476.     "@Group" bentry,
  477.     "Other layout"    message "\nLayout: " set Q0 bentry,
  478.     "@= (center line)" tosol insert "@=",
  479.     "@> (flush right)" insert "@>",
  480.     "@/ (tab stop)" insert "@/",
  481.     "@^ (set tab stop)" insert "@^",
  482.     "@PageFooting" insert 
  483.         "@PageFooting(left=\"\", center=\"\", right=\"\")\n"
  484.         24 r c,
  485.     "H-@PageHeading" insert
  486.         "@PageHeading(left=\"\", center=\"\", right=\"\")\n"
  487.         24 r c,
  488.     "@BlankPage" insert Q0 "\n",
  489.     "@NewPage" insert Q0 "\n")
  490.  
  491. NotesMenu : imenu "Notes/Reference" (
  492.     "@Foot" centry,
  493.     "@Index" centry,
  494.     "@Label" 0->select centry Q3 "Name of tag" insert Q3 c,
  495.     "@Note" centry,
  496.     "@PageRef" 0->select centry Q3 "Name of tag" insert Q3 c,
  497.     "@Ref" 0->select centry Q3 "Name of tag" insert Q3 c,
  498.     "@Tag" 0->select centry Q3 "Name of tag" insert Q3 c,
  499.     "@Under" centry)
  500.  
  501. StyleMenu : imenu "Style Options" (
  502.         "LeftMargin",
  503.         "RightMargin",
  504.         "TopMargin",
  505.         "BottomMargin",
  506.         "Font",
  507.         "Fill",
  508.         "Indent",
  509.         "Justify",
  510.         "LineWidth",
  511.         "PaperLength",
  512.         "PaperWidth",
  513.         "Spacing",
  514.         "Spread",
  515.         "TabSize")
  516.     FileStart
  517.     if (1 match "@style(" || search "\n@style(")
  518.         (found search ")")
  519.     else (r toend
  520.         if (1 match "@make" || 1 match "@format") (Down)
  521.         insert "@style()\n" r c r c)
  522.     draw
  523.     r c current = '(' ? c : (c ", ")
  524.     insert Q0 " = "
  525.     
  526. ; Accents
  527.  
  528. ScribeFormatMenu : menu "Scribe Menu" (
  529.     "@Typefaces"    TypefacesMenu,
  530.     "@Divisions"    DivisionsMenu,
  531.     "@Layout"      LayoutMenu,
  532.     "@Notes/Ref"    NotesMenu,
  533.     "@Style"       StyleMenu
  534.     )
  535.  
  536.